import java.util.Arrays;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Executors;

/**
 * @auther zhouliangliang
 * @date 2022/10/19 10:28
 * @description
 */
public class Delete {

    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6,7,8,9,10};
        new Delete().reverse(array.length, 4, array);
    }

    public void output(int[] array) {
        Arrays.stream(array).forEach(item->{
            System.out.print(item + " ");
        });
    }

    public int[] reverse(int n, int m, int[]array) {
//        [1,2,3,4,5,6,7,8,9,10]
//第一步，全部反转      [10,9,8,7,6,5,4,3,2,1]
//第二步，反转前边m个   [7,8,9,10,6,5,4,3,2,1], 下标(0 - (m-1))
//第三步，反转后边n-m个 [7,8,9,10,1,2,3,4,5,6], 下标(m - n-1)
         m = m % n;
         rev(array, 0, n-1);
         rev(array, 0, m-1);
         rev(array, m, n-1);
         output(array);

         return array;
    }

    public void rev(int[] array, int start, int end) {
        while (start < end) {
            doRev(start++, end--, array);
        }
    }

    public void doRev(int start, int end, int[] array) {
        int temp = array[start];
        array[start] = array[end];
        array[end] = temp;
    }
}
